///**
// * 
// */
//package com.leyu.mall.admin.search.controller;
//
//import java.util.Collection;
//import java.util.Collections;
//import java.util.LinkedHashMap;
//import java.util.LinkedList;
//import java.util.List;
//import java.util.Map;
//
//import javax.annotation.Resource;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//
//import com.leyu.mall.domain.goods.GoodsBase;
//import com.leyu.mall.domain.goods.GoodsBrand;
//import com.leyu.mall.domain.goods.GoodsMobile;
//import com.leyu.mall.service.cms.ICmsChannelService;
//import com.leyu.mall.service.goods.IGoodsAlbumService;
//import com.leyu.mall.service.goods.IGoodsBaseService;
//import com.leyu.mall.service.goods.IGoodsBrandService;
//import com.leyu.mall.service.goods.IGoodsCategoryService;
//import com.leyu.mall.service.goods.IGoodsMobileService;
//import com.leyu.mall.service.goods.IGoodsRelationService;
//import com.leyu.mall.service.mdm.IMDMColorService;
//import com.leyu.mall.service.mdm.IMDMFeatureService;
//import com.leyu.mall.service.mdm.IMDMOSService;
//import com.leyu.mall.service.mdm.IMDMPriceRegionService;
//import com.leyu.mall.service.mdm.IMDMProvinceService;
//import com.leyu.mall.service.mdm.IMDMScreenSizeService;
//import com.leyu.mall.service.mdm.IMDMStorageService;
//import com.leyu.search.index.domain.GoodsIndexItem;
//import com.leyu.search.service.GoodsSearchService;
//
///**
// * @author change
// * 
// */
//@Controller
//@RequestMapping("admin/search")
//public class SearchAdminController {
//	static Logger logger = LoggerFactory.getLogger(SearchAdminController.class);
//	@Resource
//	private IGoodsBaseService goodsBaseServiceImpl;
//	@Autowired
//	private IGoodsBrandService goodsBrandServiceImpl;
//	@Autowired
//	private IGoodsCategoryService goodsCategoryService;
//	@Autowired
//	private ICmsChannelService cmsChannelService;
//
//	@Autowired
//	private IGoodsRelationService goodsRelationServiceImpl;
//	@Autowired
//	IGoodsAlbumService goodsAlbumServiceImpl;
//
//	@Autowired
//	IGoodsMobileService goodsMobileServiceImpl;
//
//	@Autowired
//	IMDMProvinceService mdmProvinceServiceImpl;
//	@Autowired
//	IMDMPriceRegionService mdmPriceRegionServiceImpl;
//
//	@Autowired
//	IMDMOSService mdmOsServiceImpl;
//	@Autowired
//	IMDMColorService mdmColorServiceImpl;
//	@Autowired
//	IMDMScreenSizeService mdmScreensizeServiceImpl;
//
//	@Autowired
//	IMDMStorageService mdmStorageServiceImpl;
//	@Autowired
//	IMDMFeatureService mdmFeatureServiceImpl;
//	@Autowired
//	GoodsSearchService goodsSearchService;
//	Map<Long, GoodsBrand> brandMap;
//
//	@RequestMapping(value = "rebuildIndex", method = { RequestMethod.GET })
//	public String buildIndex() {
//		return "admin/search.html";
//	}
//
//	@RequestMapping(value = "rebuildIndex", method = { RequestMethod.POST })
//	public String buildIndex(Form form) {
//		goodsSearchService.removeAllIndex();
//
//		try {
//			List<GoodsBase> goodsList = goodsBaseServiceImpl.getAllGoodsBase();
//			Collection<GoodsIndexItem> indexedDatas = this
//					.convertToIndexDatas(goodsList);
//			goodsSearchService.addToIndex(indexedDatas);
//		} catch (Exception e) {
//			logger.error("fetch goods failure!", e);
//		}
//		/*
//		 * Long startId=0L; int limitSize=10000; int maxId=getMaxGoodsId();
//		 * 
//		 * while(startId<maxId){ maxId=getMaxGoodsId();
//		 * Collection<GoodsIndexItem> datas=this.getDatas(startId, limitSize);
//		 * if(datas!=null&&datas.size()>0){
//		 * startId=this.getMaxGoodsIdInBatch(datas); }else{ break; } }
//		 */
//		return "admin/search.html";
//	}
//
//	Collection<GoodsIndexItem> convertToIndexDatas(List<GoodsBase> datas)
//			throws Exception {
//		if (datas == null || datas.isEmpty()) {
//			return Collections.EMPTY_LIST;
//		}
//		Collection<GoodsIndexItem> indexDatas = new LinkedList<GoodsIndexItem>();
//		List<GoodsMobile> goodsMobileList = goodsMobileServiceImpl
//				.getAllGoodsMobile();
//		List<GoodsBrand> goodsBrandList = goodsBrandServiceImpl
//				.getAllGoodsBrand();
//		Map<Long, GoodsMobile> goodsMobileMap = this.toMap(goodsMobileList);
//		brandMap=this.toBrandMap(goodsBrandList);
//		for (GoodsBase goods : datas) {
//			GoodsMobile goodsMobile = goodsMobileMap.get(goods.getGoodsId()); 
//			if(goodsMobile==null){
//				continue;
//			}
//			GoodsIndexItem item = this.convert(goods, goodsMobile);
//			indexDatas.add(item);
//		}
//		return indexDatas;
//	}
//
//	private Map<Long, GoodsMobile> toMap(List<GoodsMobile> goodsMobileList) {
//		Map<Long, GoodsMobile> datas = new LinkedHashMap<Long, GoodsMobile>();
//		for (GoodsMobile item : goodsMobileList) {
//			datas.put(item.getGoodsId(), item);
//		}
//		return datas;
//	}
//	private Map<Long, GoodsBrand> toBrandMap(List<GoodsBrand> goodsBrandList) {
//		Map<Long, GoodsBrand> datas = new LinkedHashMap<Long, GoodsBrand>();
//		for (GoodsBrand item : goodsBrandList) {
//			datas.put(item.getBrandID(), item);
//		}
//		return datas;
//	}
//
//	private GoodsIndexItem convert(GoodsBase goods,GoodsMobile goodsMobile){
//		
//		GoodsIndexItem indexItem=new GoodsIndexItem();
//		GoodsBrand goodsBrand=brandMap.get(Long.valueOf(goods.getBrandId()));
//		indexItem.setId(goods.getGoodsId()+"");
//		
//		indexItem.setCateId3(goods.getCategoryId());
//		indexItem.setPrice(goods.getShopPrice()==null?0:goods.getShopPrice().floatValue());
//		
//		indexItem.areaId=goodsMobile.getAreaId();
//		indexItem.setArea(goodsMobile.getAreaName());
//		
//		indexItem.setBrandId(Long.valueOf(goods.getBrandId()));
//		indexItem.setBrand(goodsBrand.getBrandName());
//		
//		indexItem.priceRangeId=goodsMobile.getPriceRegionId();
//		
//		indexItem.setSystemId(1L);//TODO fixed me
//		indexItem.setSystem(goodsMobile.getMobileOs());
//		indexItem.setName(goods.getGoodsName());
//		/*indexItem.screenSizeId=goodsMobile.get;
//		indexItem.specialId=goodsMobile.get	;*/
//		
//		/*indexItem.setOpenDateTime(goods);//TODO fixed me
//		indexItem.setSoldQuantity(soldQuantity);
//		indexItem.setSpecialId(specialId);
//		indexItem.setSpecials(specials);*/
//		
//		
//		/*indexItem.setCommentsCount(goods.get)*/
//		return indexItem;
//	}
//
//	/*
//	 * 
//	 * private int getMaxGoodsId() { return 0;
//	 * 
//	 * }
//	 * 
//	 * private Long getMaxGoodsIdInBatch(Collection<GoodsIndexItem> datas) {
//	 * Long maxId = 0L; for (GoodsIndexItem item : datas) { Long id =
//	 * Long.valueOf(item.getId()); if (maxId < id) { maxId = id; } } return
//	 * maxId; }
//	 * 
//	 * Collection<GoodsIndexItem> getDatas(Long startId, int limitSize) {
//	 * 
//	 * return null; }
//	 */
//
//	public static class Form {
//	}
//}
